<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>AI的猜测结果</title>
    <style>
      body {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 20px;
        font-family: Arial, sans-serif;
        background-color: #f5f5f5;
        min-height: 100vh;
        margin: 0;
      }

      .container {
        background: white;
        padding: clamp(15px, 4vw, 30px);
        border-radius: 12px;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        max-width: 800px;
        width: 95%;
        margin: 20px auto;
        text-align: center;
        animation: slideIn 0.5s ease-out;
      }

      @keyframes slideIn {
        from {
          opacity: 0;
          transform: translateY(-20px);
        }
        to {
          opacity: 1;
          transform: translateY(0);
        }
      }

      .result-title {
        font-size: clamp(20px, 5vw, 28px);
        color: #333;
        margin-bottom: 20px;
        padding-bottom: 15px;
        border-bottom: 3px solid #4caf50;
      }

      .result-content {
        font-size: clamp(18px, 4vw, 24px);
        color: #4caf50;
        padding: clamp(15px, 3vw, 20px);
        background: #f8f8f8;
        border-radius: 8px;
        margin: 20px 0;
        font-weight: 500;
        animation: fadeIn 0.5s ease-in;
      }

      .result-image-container {
        position: relative;
        margin: 20px 0;
        padding: 10px;
        background: white;
        border-radius: 12px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        overflow: hidden;
      }

      .result-image {
        max-width: 100%;
        height: auto;
        border-radius: 8px;
        display: block;
        margin: 0 auto;
        background: white;
      }

      .buttons {
        margin-top: 30px;
        display: flex;
        gap: clamp(10px, 2vw, 20px);
        justify-content: center;
        flex-wrap: wrap;
        padding: 0 10px;
        width: 100%;
        box-sizing: border-box;
      }

      .button {
        padding: clamp(8px, 2vw, 12px) clamp(16px, 3vw, 24px);
        font-size: clamp(14px, 3vw, 18px);
        border: none;
        border-radius: 6px;
        cursor: pointer;
        transition: all 0.3s;
        text-decoration: none;
        color: white;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: clamp(100px, 20vw, 150px);
        max-width: 100%;
        white-space: nowrap;
        box-sizing: border-box;
        flex: 1;
      }

      .back-button {
        background: #2196f3;
      }

      .back-button:hover {
        background: #1976d2;
        transform: translateY(-2px);
      }

      .new-drawing {
        background: #4caf50;
      }

      .new-drawing:hover {
        background: #45a049;
        transform: translateY(-2px);
      }

      .loading {
        font-size: clamp(16px, 3.5vw, 20px);
        color: #666;
        margin: 20px 0;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
      }

      .loading::after {
        content: "";
        width: clamp(15px, 3vw, 20px);
        height: clamp(15px, 3vw, 20px);
        border: 3px solid #f3f3f3;
        border-top: 3px solid #4caf50;
        border-radius: 50%;
        animation: spin 1s linear infinite;
        display: inline-block;
      }

      @keyframes spin {
        0% {
          transform: rotate(0deg);
        }
        100% {
          transform: rotate(360deg);
        }
      }

      @keyframes fadeIn {
        from {
          opacity: 0;
        }
        to {
          opacity: 1;
        }
      }

      .error-message {
        color: #f44336;
        font-size: clamp(14px, 3vw, 18px);
        margin: 20px 0;
        padding: 15px;
        background: #ffebee;
        border-radius: 8px;
        border-left: 4px solid #f44336;
      }

      @media (max-width: 600px) {
        .container {
          padding: 15px;
          margin: 10px auto;
          width: 90%;
        }

        .buttons {
          flex-direction: column;
          align-items: stretch;
          padding: 0;
          gap: 15px;
        }

        .button {
          width: 100%;
          min-width: unset;
          margin: 0;
          padding: 12px 20px;
        }
      }

      @media (max-width: 400px) {
        body {
          padding: 10px;
        }

        .container {
          padding: 10px;
          margin: 5px auto;
          width: 95%;
        }

        .result-image-container {
          padding: 5px;
        }

        .button {
          font-size: 16px;
          padding: 10px 16px;
        }
      }
    </style>
  </head>
  <body>
    <div class="container">
      <h1 class="result-title">AI的猜测结果</h1>
      <div id="resultContent" class="result-content">
        <div class="loading">正在加载结果...</div>
      </div>
      <div class="result-image-container">
        <div style="background: white; padding: 10px;">
          <img id="resultImage" class="result-image" src="" alt="您的绘画" />
        </div>
      </div>
      <div class="buttons">
        <a href="/" class="button back-button">返回画板</a>
        <a href="#" class="button new-drawing" id="saveDrawingBtn">保存绘画</a>
      </div>
    </div>

    <script>
      document.addEventListener("DOMContentLoaded", () => {
        // 从注入的数据中获取结果
        const { result, image } = window.RESULT_DATA || {};
        const resultContent = document.getElementById("resultContent");
        const resultImage = document.getElementById("resultImage");
        const saveDrawingBtn = document.getElementById("saveDrawingBtn");

        // 显示结果
        if (result) {
          resultContent.innerHTML = `
            <div style="font-size: 24px; margin-bottom: 10px;">AI认为你画的是：</div>
            <div style="font-size: 32px; color: #1976d2; font-weight: bold;">${result}</div>
          `;
        } else {
          resultContent.innerHTML = `
            <div class="error-message">
              抱歉，没有获取到识别结果
            </div>
          `;
        }

        // 显示图片
        if (image) {
          resultImage.src = image;
          resultImage.style.display = "block";
          
          resultImage.onload = () => {
            document.querySelector(".result-image-container").style.display = "block";
          };
        } else {
          document.querySelector(".result-image-container").style.display = "none";
        }

        // 添加错误处理
        resultImage.onerror = () => {
          document.querySelector(".result-image-container").style.display = "none";
        };

        // 添加保存绘画功能
        saveDrawingBtn.addEventListener("click", (e) => {
          e.preventDefault();
          if (image) {
            const link = document.createElement("a");
            link.download = `我的绘画_${new Date().toISOString().slice(0, 10)}.jpg`;
            link.href = image;
            link.click();
          } else {
            alert("没有可保存的绘画");
          }
        });
      });
    </script>
  </body>
</html>
